home *** CD-ROM | disk | FTP | other *** search
- Path: bristlecone.together.net!usenet
- From: John Wagner <jwag@together.net>
- Newsgroups: comp.lang.c++
- Subject: Re: Pointers HELP!!!!
- Date: Tue, 23 Jan 1996 19:29:35 +0000
- Organization: TGF Internet Services
- Message-ID: <3105371F.83F@together.net>
- References: <31055e1d.1020193@news.pi.se>
- NNTP-Posting-Host: vtr-npt102.ramp.together.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win95; I; 16bit)
-
- Satai Delenn wrote:
-
- > ////////////////////////////////////////////////////
- > class B
- > {
- > public:
- > PFUNC m_callback;
- > public:
- > B(PFUNC callback) {
- > m_callback = callback;
- > *m_callback(10);
- > }
- > ~B(){};
- > };
- > ////////////////////////////////////////////////////
- >
- > I know this doesnt work, so please ne1 help me out here.
-
- Yep, this doesn't work. A non-static member function accepts a "hidden" pointer to
- the instance of it's class, called the "this" pointer. So the signature for the
- callback in the class A is really: void callback(A *this, int error). Your
- defination in the class B of the callback doesn't show a function with a parameter
- list that accepts a class A (or an int for that matter).
-
- You have two choices (as I see it). Make the callback function in class A static
- (and fix the parameter list of callback in class B to accept an int), or pass a
- pointer to a class A to the constructor of class B (and have an A* as a member of
- class B) instead of a pointer to a function within a class A.
-
- To be brutally honest, it looks like a poor design and I would consider re-thinking
- the problem.
-
- Hope this helps,
- John
- jwag@together.net
-